(function (factory) {
    if (typeof define === "function" && define.amd) {
        define(["jquery", "../jquery.validate"], factory);
    } else {
        factory(jQuery);
    }
}(function ($) {
    $.extend($.validator.messages, {
        required: "*必填",
        remote: "*错误",
        email: "请输入有效的电子邮件地址",
        url: "请输入有效的网址",
        date: "请输入有效的日期",
        dateISO: "请输入有效的日期 (YYYY-MM-DD)",
        number: "请输入有效的数字",
        digits: "只能输入数字",
        creditcard: "请输入有效的信用卡号码",
        equalTo: "你的输入不相同",
        extension: "请输入有效的后缀",
        maxlength: $.validator.format("最多可以输入 {0} 个字符"),
        minlength: $.validator.format("最少要输入 {0} 个字符"),
        rangelength: $.validator.format("请输入长度在 {0} 到 {1} 之间的字符串"),
        range: $.validator.format("请输入范围在 {0} 到 {1} 之间的数值"),
        max: $.validator.format("请输入不大于 {0} 的数值"),
        min: $.validator.format("请输入不小于 {0} 的数值")
    });

}));

layui.config({
    base: 'js/layuiadmin/' //静态资源所在路径
}).extend({
    index: 'lib/index' //主入口模块
}).use(['index', 'table'], function () {
    var $ = layui.$
        , table = layui.table
        , admin = layui.admin;

    $(".sendSms").on('click', function () {
        var tel = $("#tel").val();
        if (!tel) {
            layer.msg("请输入手机号码!");
        } else {
            $.ajax({
                type: "get",
                url: telUrl,
                data: {tel:tel},
                dataType: "json",
                async: false,
                error: function (data) {
                    layer.msg("发送失败，请稍候再试!");
                },
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg("手机验证码已发送，请注意查收!");
                    } else {
                        layer.msg("发送失败，请稍候再试!");
                    }
                }
            });
        }
    });
});
$.validator.setDefaults({
    submitHandler: function () {
        var username = $("#username").val();
        var tel = $("#tel").val();
        var content = $("#content").val();
        var yzm = $("#yzm").val();
        var typeName = $("#typeName").val();

        $.ajax({
            type: "get",
            url: insertUrl,
            data: {
                username:username,
                typeName:typeName,
                tel:tel,
                content:content,
                verifyCode:yzm,
            },
            dataType: "json",
            async: false,
            error: function (data) {
                // layer.msg("发送失败，请稍候再试!");
                console.log(data);
            },
            success: function (data) {
                console.log(data);
                if (data.code == 0) {
                    //     console.log(data.status);
                    layer.msg("提交成功!客服将在48小时内联系内联系您");
                } else {
                    layer.msg(''+data.msg());
                }
            }
        });
    }
});
$().ready(function () {
    $("#commentForm").validate({
        debug: true,
        rules: {
            username: {
                required: true,
                minlength: 2
            },
            tel: {
                required: true,
                minlength: 11
            },
            yzm: {
                required: true,
                minlength: 6,
                maxlength: 6,
            }
        },
        messages: {
            username: {
                required: "输入姓名",
                minlength: "姓名至少2个字"
            },
            tel: {
                required: "请输入手机号",
                minlength: "密码长度不能小于 5 个字母"
            },
            yzm: {
                required: "",
                minlength: ""
            },
            confirm_password: {
                required: "请输入密码",
                minlength: "密码长度不能小于 5 个字母",
                equalTo: "两次密码输入不一致"
            },
            email: "请输入一个正确的邮箱",
            agree: "请接受我们的声明",
            topic: "请选择两个主题"
        }
    });
});